using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class BrandHeadCtrl : UserHeadCtrlBase
	{
		private const string TAG = "BrandHeadCtrl";
		private bool mBIsFirstLoaded = true;
		public new static DependencyProperty ItemObjectProperty = DependencyProperty.Register("ItemObject", typeof(Contact), typeof(BrandHeadCtrl), new PropertyMetadata(null, new PropertyChangedCallback(BrandHeadCtrl.OnItemObjectPropertyChanged)));
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		public SnsHttpImgCtrlBase mHttpHeadCtrl;
		internal Button LayoutRoot;
		internal Image imgHead;
		private bool _contentLoaded;
		public event MMUIEvent mDlgHeadClicked;
		public Contact ItemObject
		{
			get
			{
				return (Contact)base.GetValue(BrandHeadCtrl.ItemObjectProperty);
			}
			set
			{
				base.SetValue(BrandHeadCtrl.ItemObjectProperty, value);
			}
		}
		public BrandHeadCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private static void OnItemObjectPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == BrandHeadCtrl.ItemObjectProperty)
			{
				(dependencyObject_0 as BrandHeadCtrl).ItemObjectPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void ItemObjectPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.RefreshItem();
			}
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void LayoutRoot_mClicked(object sender, object args)
		{
			if (this.mDlgHeadClicked != null)
			{
				this.mDlgHeadClicked(this, this.ItemObject);
				return;
			}
			object[] object_ = new object[]
			{
				this.ItemObject
			};
			ToolFunction.GotoPageForUserControl("/Source/UI/Contact/VerifiedPeopleInfo.xaml", object_, false);
		}
		public void RefreshItem()
		{
			if (this.ItemObject == null)
			{
				this.imgHead.set_Source(null);
				return;
			}
			Contact contact = StorageMgr.contact.method_0(this.ItemObject.strUsrName);
			if (contact != null)
			{
				this.ItemObject.strBrandIconURL = contact.strBrandIconURL;
				this.ItemObject.nImgFlag = contact.nImgFlag;
			}
			if (!string.IsNullOrEmpty(this.ItemObject.strBrandIconURL))
			{
				this.mHttpHeadCtrl = new SnsHttpImgCtrlBase();
				snsMediaDownloadInfo objReqInfo = new snsMediaDownloadInfo
				{
					snsObjID = 0uL,
					string_0 = this.ItemObject.strBrandIconURL,
					urlType = SnsUrlType.MMSNS_URL_CDN,
					priority = SnsPriority.LOW
				};
				this.mHttpHeadCtrl.mDlgObjectGetted += new MMUIEvent(this.mHttpHeadCtrl_mDlgObjectGetted);
				this.mHttpHeadCtrl.StartRequest(objReqInfo, true);
				return;
			}
			base.StartRequest(this.ItemObject.strUsrName);
		}
		private object mHttpHeadCtrl_mDlgObjectGetted(object sender, object object_0)
		{
			if (object_0 != null && object_0 is BitmapImage)
			{
				this.imgHead.set_Source(object_0 as BitmapImage);
				if (this.mHttpHeadCtrl != null)
				{
					this.mHttpHeadCtrl.StopRequest();
					this.mHttpHeadCtrl.mDlgObjectGetted -= new MMUIEvent(this.mHttpHeadCtrl_mDlgObjectGetted);
					this.mHttpHeadCtrl = null;
				}
				return null;
			}
			return null;
		}
		protected override void ObjectCome(string strUser)
		{
			base.ObjectCome(strUser);
			this.imgHead.set_Source(HeadImageMgr.getHeadImage(strUser));
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ProfileInfo/BrandHeadCtrl.xaml", 2));
			this.LayoutRoot = (Button)base.FindName("LayoutRoot");
			this.imgHead = (Image)base.FindName("imgHead");
		}
	}
}
